package com.example.superoa.controller;

import java.util.HashMap;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.example.superoa.model.service.RhireService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;

@Controller
public class RhireController {
	@Autowired
	private RhireService hireservice;
	
	//查询录用	
	@PostMapping("select-offer")
	@ResponseBody
	public Map<String,Object> show(int page,int rows) {
		Map<String,Object> map = new HashMap<>();
		//先分页
		Page<Object> pg = PageHelper.startPage(page, rows);
		JSONArray j = hireservice.hirefindAlls();
		int i=1;
		for (Object object : j) {
			JSONObject obj=(JSONObject)object;
			obj.put("hirexh", i);
			i++;
		}
		//总记录
		map.put("total", pg.getTotal());
		//页内容
		map.put("rows", j);
		return map;
	}
	//根据面试人姓名查询录用
		@PostMapping("select-name")
		@ResponseBody
		public Map<String,Object> showname(String reasyname,int page,int rows) {
			Map<String,Object> map = new HashMap<>();
			//先分页
			Page<Object> pg = PageHelper.startPage(page, rows);
			JSONArray j = hireservice.hirefindByname(reasyname);
			int i=1;
			for (Object object : j) {
				JSONObject obj=(JSONObject)object;
				obj.put("hirexh", i);
				i++;
			}
			//总记录
			map.put("total", pg.getTotal());
			//页内容
			map.put("rows", j);
			return map;
		}
	//点击查看详情显示
	@RequestMapping("hire-xiangq")
	@ResponseBody
	public JSONArray xiangq(int reasyid) {
		return hireservice.findBybioId(reasyid);		
	}
	//发送到人事部
	@RequestMapping("fasong-staff")
	@ResponseBody
	public void inform(Integer id) {
		 hireservice.tongzhistaff(id);
	}
}